//	ID : pallab81
// 	PROG : 544
// 	LANG : C++
// 	2011-09-12-17.38.14 Monday
//
// 	"I have not failed, I have just found 10000 ways that won't work.
//


#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstring>
#include <cstdlib>

using namespace std;

#define VI vector< int >
#define CI( x ) scanf("%d",&x)
#define CL( x ) scanf("%lld",&x)
#define CD( x ) scanf("%lf",&x )
#define fo(i,st,ed) for(int i = st ; i < ed ; ++i )
#define foE(i,st,ed) for(int i = st ; i <= ed ; ++i )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip system("pause")
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define f first
#define s second
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )

inline void wait( double seconds ){
    double endtime = clock()+( seconds* CLOCKS_PER_SEC );
    while( clock() < endtime ){
        ;
    }
}
//UNION FIND STARTED
const int inf = (int)1e6;
int root[inf+10];
int rank[inf+10];
inline void _Set(){
    foE(i,0,inf){
       root[i]=i;
       rank[i]=0;
    }
}
inline int _Find(int x){
    if( x!= root[x] ){
        root[x] = _Find( root[x] );
    }
return root[x];
}
inline void _Union(int x, int y){
    int px = _Find(x);
    int py = _Find(y);
    if( rank[px] > rank[py] ){
        root[py] = px;
    }
    else{
        root[px]=py;
    }
    if( rank[px]==rank[py] ){
        rank[py]+=1;
    }
}

//UNION FIND ENDS
int nodes,edges,k;
map<string,int> id;
string source,sink;
int sourceid,sinkid;
struct NODE{
        int x,y,cc;
        NODE(int x_, int y_, int cc_):
        x(x_),y(y_),cc(cc_){;}
};
vector< NODE > vt;
inline void Read(){
    int city=0;
    id.clear();
    vt.clear();
    string name1,name2;
    int cc;
    int x,y;
    fo(i,0,edges){
        cin>>name1>>name2>>cc;
        if( id.count(name1) ){
            x=id[name1];
        }
        else{
            x=city;
            id[name1]=city;
            ++city;
        }
        if( id.count(name2) ){
            y=id[name2];
        }
        else{
            y=city;
            id[name2]=city;
            ++city;
        }
        vt.pb( NODE(x,y,cc) );
    }
    cin>>source>>sink;
    sourceid = id[ source ];
    sinkid = id[sink];
    vt.pb( NODE(sourceid,sourceid,(int)20000) );
}
inline bool cmp(NODE A, NODE B){
    return A.cc > B.cc;
}
inline void Proc(){
    _Set();
    sort(vt.begin(),vt.end(),cmp);
    int max_load=0;
    bool firstt=true;
    for(int i=0; i<edges+1 ; ++i){
        int x = vt[i].x;
        int y = vt[i].y;
        int cc = vt[i].cc;

        if( _Find(x)!=_Find(y) ){
            _Union(x,y);
            if( firstt ){
                firstt=false;
                max_load=cc;
            }
            else{
                max_load = min(max_load,cc);
            }
            if( _Find(sourceid) == _Find(sinkid) ){
                break;
            }
        }
    }
    printf("Scenario #%d\n%d tons\n\n",k,max_load);
}

int main(){
    #ifndef ONLINE_JUDGE
        freopen("in.txt","rt",stdin);
    #endif
    k=1;
    while( scanf("%d %d",&nodes,&edges) == 2 ){
        if( nodes==0 && edges==0 )break;
        Read();
        Proc();
        ++k;
    }

return 0;
}
